home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / Chip_2004-11_cd1.bin / zkuste / dolby / download / dvdlab / DVDlabProRC2b.exe / {app} / Extras / Script / fade.talk < prev    next >
Text File  |  2004-03-22  |  3KB  |  116 lines

  1. /*    Linear Fade 1.0
  2.     by Oscar, 12 Dec 2003
  3.     
  4.     To run this: DROP the Script from Assets to the Object in Menu.
  5.     
  6.     this example creates a simple Linear Fade on any object
  7.     You can choose the direction
  8.     Note: because of the bitmap merging, the text will become not-editable after you apply this
  9. */
  10.  
  11. // Get the current menu and selected object when you drag and drop script
  12. // Note: if testing from Script editor make sure you have just one menu opened on desktop,
  13. //       in such case the MenuGetCurSel will return currently opened menu 
  14. menu = MenuGetCurSel() 
  15. // VTS menu 1..255, VMG menu 10001..10255 
  16.  
  17. // show the current menu on top of all others
  18. MenuActivate(menu)
  19.  
  20. object= ObjectGetCurSel(menu) 
  21.  
  22. if (object==0) then
  23.     print "No object Selected"
  24.     end
  25. endif
  26.  
  27. type = LoadInteger("FadeType",0)
  28.  
  29. input "Direction:Vertical Bottom->Top|Horizontal Right->Left|Vertical Top->Bottom|Horizontal Left->Right",type //"CHECK:/FILE:/COLOR:/Combo:item1|item2... 
  30.     
  31. //allow cancel    
  32. if bCancelInput then
  33.     trace "Cancelled"
  34.     end
  35. endif
  36.     
  37. // save grad type to registry
  38. SaveInteger("FadeType",type)
  39.     
  40. //get the image buffer from object and store it in buffer 1
  41. ImgGrabObject(1,menu,object) // imgNum = temporary image buffer 1,2 or 3
  42.  
  43. imgW = ImgGetWidth(1) 
  44. imgH = ImgGetHeight(1)
  45.  
  46. //vertical
  47. steps = imgH
  48.  
  49. //horizontal
  50. if (type==1 | type==3) then
  51.     steps = imgW
  52. endif
  53.  
  54. // one of the parameter in equation has to be float or else the result will be integer
  55. // we will make the steps float number. 
  56. ca = 255.0/FLOAT(steps)
  57.  
  58. // if the other dirrection, make it negative (from 255 +(-ca) to 00)
  59. if type>1 then
  60.     ca=-ca
  61. endif
  62.  
  63. // trace is same as print, but it will appear only in the Output window in editor
  64. trace "Steps =",steps, "ca=",ca
  65.  
  66. // this is interpreter so it is slow!
  67. // show some progress or else people will see nothing happening for while
  68. ProgressBar(0,imgH,"Building Linear Alpha Mask")
  69.  
  70.  
  71. // loop through each pixel and draw the Alpha channel
  72. // we have to combine the new gradient alpha with any existing alpha on the object
  73. // if type = 0,1 we go AA=0 to 255,if 2,3, then we go the other way from AA=255 to 0
  74.  
  75. if (type==0 | type==2) then
  76.     
  77.     // VERTICAL *******************************
  78.     AA=0
  79.     if type>1 then
  80.         AA=255
  81.     endif
  82.  
  83.     for y=1 to imgH
  84.         AA=AA+ca
  85.         ProgressSetPos(y)
  86.         for x=1 to imgW
  87.             mix = ImgGetA(1,x,y)//,AA)
  88.             mix = MIN(mix,AA)
  89.             ImgSetA(1,x,y,mix )
  90.         next x
  91.         
  92.     next y
  93. else
  94.     // HORIZONTAL **************************
  95.     for y=1 to imgH
  96.         AA=0
  97.         if type>1 then
  98.             AA=255
  99.         endif
  100.         ProgressSetPos(y)
  101.         
  102.         for x=1 to imgW
  103.             AA=AA+ca
  104.             mix = ImgGetA(1,x,y)
  105.             mix = MIN(mix,AA)
  106.             ImgSetA(1,x,y,mix)
  107.         next x
  108.     next y
  109.  
  110. endif
  111.  
  112. // now put the img buffer 1 into the object!
  113. ImgSetToObject(1,menu,object)
  114. // remove any shadow
  115. ObjectSetShadow(menu,object,0,0)
  116.